Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

208
Vistas
Javascript: using "!!" in boolean context

Is there any reason to use !!someValue (which is equivalent to Boolean(someValue)) in a boolean context? In other words, in situations like if (someValue) ..., does it make sense to write if (!!someValue) ...?

It hurts my eyes and I think it's redundant, but I want to verify that there aren't any edge cases that require it - because I came across a codebase where this seems to be the default way of checking for truthiness.

Clarification: yes, in the general case !!someValue will convert someValue to a boolean; I'm referring to contexts where the runtime will automatically convert someValue to true or false.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

That's a helpful way of converting any data type into boolean; The exact synonym would be:

Boolean(someValue)

Some prefer the 'double bang' as being more coincise, while others prefer the classic conversion with Boolean(someValue) for better readability.

So returning to your question, it's most likely redundant in conditions, but it can be handy when needing a conversion from any type to boolean.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Can't say I know why anyone would rely on directly checking booleans rather than on truthiness, but there is at least one scenario where truthiness is different than coercing with !!.

console.log([] == false); // true
console.log(!![] == false); // false
if([]) { console.log(true); } // true
if([] == false) { console.log(true); } // true
if(!![] == false) { console.log(true); } else { console.log(false); } // false

about 4 years ago · Juan Pablo Isaza Denunciar

0

You never need to use a double bang to convert a boolean value to boolean.

boolean === !!boolean
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda